/*************************************************************************
 *
 * $Id: data.h 67 2006-07-30 15:30:03Z alpov $
 * 
 *************************************************************************/         

#ifndef _DATA_H
#define _DATA_H

#define MAX_DESC_LEN        16
#define SENSOR_MAX_COUNT    16
#define MODE_MAX_COUNT      8


/* popisy senzoru a rezimu, jejich pocet; read only pro terminal
 * pristup z PC: DESC-READ(one), DESC-WRITE(one)
 */  
typedef struct {
    unsigned char sensor_count;
    char sensor_desc[SENSOR_MAX_COUNT][MAX_DESC_LEN];
    unsigned char mode_count;
    char mode_desc[MODE_MAX_COUNT][MAX_DESC_LEN];
} DESC_STRUCT;


/* udaje ukladane lokalne do EEPROM terminalu; read-write pro terminal
 * pristup z terminalu: klavesnice
 */ 
typedef struct {
    unsigned char addr;
    signed char contrast;
    unsigned char sensor_index;
#if (DISPLAY == 1602)
    unsigned char info_index;
#elif (DISPLAY == 2004)
    unsigned char sensor_index2;
#endif
    unsigned char reset;
} EEDATA_STRUCT;


/* informativni udaje predavane mozkem periodicky do vsech klientu; read only pro terminal
 * pristup z mozku: STDATA-WRITE(one)
 */ 
typedef struct {
    signed int temperature[SENSOR_MAX_COUNT];
    unsigned char io_state;
    unsigned char reg_state; // FIXME
} STDATA_STRUCT;


/* udaje nastavitelne pres menu; read-write pro terminal
 * pristup z mozku: RWDATA-READ(all,one), RWDATA-WRITE(all,one)
 * pristup do mozku: RWDATA-READ(all), RWDATA-WRITE(one)
 */  
typedef struct {
    unsigned char mode;
    signed char shift;
    unsigned char shift_length;
    signed char sw_mode;
    unsigned long sw_datetime;
    unsigned long now;
} RWDATA_STRUCT;


extern DESC_STRUCT desc;            // eeprom
extern EEDATA_STRUCT eedata;        // sram kopirovany z eeprom
extern STDATA_STRUCT stdata;        // sram
extern RWDATA_STRUCT rwdata;        // sram
extern RWDATA_STRUCT rwdata_undo;   // sram

extern Mutex DataLock;

extern void ReadEepromData(void);
extern void WriteEepromData(void);
extern void ReadEEPromBlock(void *pointer_ram, void *pointer_eeprom, unsigned char n);
extern void WriteEEPromBlock(void *pointer_ram, void *pointer_eeprom, unsigned char n);

#endif
